/*
 * @Author: Wxx
 * @Date: 2022-02-21 17:24:23
 * @LastEditors: Wxx
 * @LastEditTime: 2022-02-21 17:31:43
 * @Description:
 */
import React, { Component } from "react";

export default class App extends Component {
  state = {
    name: "冰墩墩",
  };

  static getDerivedStateFromProps(nextProps, nextState) {
    // 初始化或者state更新都会走这个生命周期方法
    console.log("getDerivedStateFromProps");
    return {
      name: nextState.name + Math.random(),
    };
  }

  render() {
    return (
      <div>
        <button
          onClick={() =>
            this.setState({
              name: "雪融融",
            })
          }
        >
          click
        </button>
        {this.state.name}
      </div>
    );
  }
}
